package com.hiray.demos.visualEffect

import android.animation.ValueAnimator
import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.util.AttributeSet
import android.view.View
import android.view.animation.DecelerateInterpolator
import com.hiray.demos.R

class ExpandLayoutActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_expan_layout)
    }
}


class ExpandLayout : View {

    val attrArray = intArrayOf(
            R.attr.expand_layout_id,
            R.attr.expand_indicator
    )

    var expandTarget: View? = null

    constructor(context: Context?) : this(context, null)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs, 0)

    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        var ta = context!!.obtainStyledAttributes(attrs, attrArray)
        if (ta.hasValue(0)) {
            var expandLayoutId = ta.getResourceId(0, 0)
            expandTarget = this@ExpandLayout.findViewById(expandLayoutId)
        }

        if (ta.hasValue(1)){

        }
    }

    fun collapse(): Unit {
        val layoutAnimator = ValueAnimator.ofInt(expandTarget!!.height, 0, 300)
        layoutAnimator.interpolator = DecelerateInterpolator()
        layoutAnimator.start()
    }
}
